package dataStructure.queue;


class Solution {
    private int rear;
    private int front;
    private int[] element;
    private int maxSize;
    private int count=0;
    public Solution(int k) {
        this.maxSize = k;
        this.rear = 0;
        this.front = 0;
        this.element=new int[k];
    }

    public boolean enQueue(int value) {

        if (isFull()){
            return false;
        }
        element[rear]=value;
        rear = (rear+1)%maxSize;
        count++;
        return true;
    }

    public boolean deQueue() {

        if (isEmpty()){
            return false;
        }
//        int temp = element[front];
        front = (front+1)%maxSize;
        count--;
        return true;
    }

    public int Front() {
        if (isEmpty()){
            return -1;
        }
        return element[front];
    }

    public int Rear() {
        if (isEmpty()){
            return -1;
        }
        int x = (rear+maxSize-1)%maxSize;
        return element[x];
    }

    public boolean isEmpty() {
        return rear == front &&count==0;
    }

    public boolean isFull() {
        return rear == front &&count==maxSize;
    }


}
